package no.project.nature;

import no.project.nature.DropBox;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
 
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

 
public class sync extends Plugin {
 
private static final String SHOW = "show";
private static final int MSG_INDEX = 0;
private String msg;
private Context context;


@Override
public PluginResult execute(String arg0, final JSONArray arg1, String arg2) {
	context = ctx.getApplicationContext();
	Log.d("ServicePlugin","Context is defined "+context);
if ( arg0.equals(SHOW) )
{
this.ctx.runOnUiThread(new Runnable()
{
public void run()
{
// try/catch generated by editor
try {
msg = arg1.getString(MSG_INDEX);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
//AlertDialog alertDialog = new AlertDialog.Builder((Context) ctx).create();
//alertDialog.setTitle("Title");
//alertDialog.setMessage(msg);
//alertDialog.show();
//DropBox dbx = new DropBox();
//dbx.onResume();
//dbx.onClickLinkToDropbox();
Intent myIntent = new Intent(context, DropBox.class);
Log.d("ServicePlugin","Intet is created");
myIntent.putExtra("text", msg);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
Log.d("ServicePlugin","With a context");
//dbx.onStart();
Log.d("Plugin", msg);
}
});
}
 
return new PluginResult(Status.OK);
}
}